<div class="model_actions_toolbar">
    <?php // $this->widget('backend.components.toolbar.MediaCategories'); ?>
</div>

<div style="text-align: center; padding: 10px;">
    <?php echo CHtml::beginForm(); ?>
    <?php
    $has_cache = Yii::app()->cache->get('cache_media_categories_for_change');
    if ($has_cache === false) {
        $datas = MediaCategory::model()->getCTreeViewDatas();
        require_once(Yii::app()->basePath . '/extensions/GraphTree/tree.php');
        $datas = dumpArrayTree($datas);
        $media_categories = array();
        if (count($datas)) {
            foreach ($datas as $data) {
                $media_categories[$data['id']] = $data['levelstr'] . '⇒ ' . strip_tags($data['text']) . '《' . (string)$data['files_count'] . '》';
            }
        }
        Yii::app()->cache->set('cache_media_categories_for_change', $media_categories, 300);
    } else {
        $media_categories = Yii::app()->cache->get('cache_media_categories_for_change');
    }

    echo CHtml::dropDownList('category_id', 0, $media_categories, array(
            'size' => 1, 'class' => 'dropdown', 'ajax' => array(
                'type' => 'GET',
                'url' => array('showUploadingZone'),
                'update' => '#uploading_zone',
                'beforeSend' => 'function() { return fnCheckSelectCategoryValue(); $("#uploading_zone").addClass("datasLoading"); }',
                'complete' => 'function() { $("#uploading_zone").removeClass("datasLoading"); }',
                ),
            'prompt' => 'Please select upload category  ......'
        ));
    ?>
    <?php
    echo CHtml::endForm();
    ?>
</div>
<div id="uploading_zone" align="center"></div>
<style type="text/css">
    div.datasLoading {
	width: 100%;
        text-align: center;
	height: 150px;
        float: right;
	text-indent: -9999em;
        background-position: center center;
        background-repeat: no-repeat;
        opacity: 1;
        background-image: url(<?php echo Yii::app()->baseUrl; ?>/assets/backend/images/ajaxLoader.gif);
    }
    div.datasLoading * {
        opacity: .2em;
    }
</style>
<script type="text/javascript">
    function fnCheckSelectCategoryValue() {
        var category_id = $('#category_id').val();
        return (isNaN(parseInt(category_id))) ? false : true;
    }
</script>
